<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      
     
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
        
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <ul class="infinite-list"  style="overflow:auto;display: grid;    place-items: center">
      <!-- <li v-for="data in fileList" class="infinite-list-item"><span v-html="data.content"></span></li> -->

      <li v-for="item in fileList" style="width:80%;display: flex; align-items: center; justify-content: center; height: 100px;background:white;" @click="jump(item)">
        <div style="width:100%;height:90px;border-color: green; border-width: 2px; border-style: solid;display: grid;background: #efeaea;">
          <!-- <span style="margin-top:10px;margin-left:20px">日期：{{item.createTime}}</span> -->
          <!-- <el-divider></el-divider> -->
          <span style="margin-left:20px">文件名称：{{item.docName}}</span>
          <span style="margin-left:20px">标题：{{item.title}}</span>
          <!-- <el-divider></el-divider> -->
          <span v-html="item.content" style="margin-left:20px;text-overflow:ellipsis;overflow:hidden"></span>
         
        </div>
      </li>
    </ul>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>


import { listByKeyword } from "@/api/business/file";
import { getToken } from "@/utils/auth";
export default {
  name: "File",
  dicts:['file_catelog','sys_del_flag'],
  components: {
    
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件信息表格数据
      fileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //view查看标志
      view:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        keyword:null,
        
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
         catelog: [
          { required: true, message: "所属目录不能为空", trigger: "blur" }
         ],
          title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
      },

    };
  },
  created() {
   // this.getList();
  },
  methods: {
    /** 查询文件信息列表 */
    getList() {
      this.loading = true;
      listByKeyword(this.queryParams).then(response => {
        this.fileList = response.rows;
        this.total = response.total;
        if(this.total==0){
           this.$modal.msgError("未找到匹配的文档数据，请重新输入关键字搜索！");
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        catelog: null,
        title: null,
        url: null,
        status: null,
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateTime: null,
        updateBy: null
      };
      this.view = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文件信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改文件信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除标题为"' + row.title + '"的数据项？').then(function() {
        return delFile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/file/export', {
        ...this.queryParams
      }, `file_${new Date().getTime()}.xlsx`)
    },
    handleUpload(row){
      this.upload.id = row.id;
       this.upload.title = "文件上传";
       this.upload.open = true;
    },
     // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "上传结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    //文件内容预览
    handleContentView(row){
      this.reset();
      const id = row.id || this.ids
      getFile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.view = true;
        this.title = "文件信息";
      });
    },
    handleDownload(row){
      //window.open(row.webUrl);
      let a = document.createElement('a');
      a.href = row.webUrl;
      a.setAttribute('download','');
      a.click();
    }
  }
};
</script>
